package com.bdqn.service.imp;

import com.bdqn.bean.Params;
import com.bdqn.bean.course.Course;
import com.bdqn.bean.course.CourseDirection;
import com.bdqn.bean.course.Minutia;
import com.bdqn.bean.course.Section;
import com.bdqn.dao.ICourseDao;
import com.bdqn.service.ICourseService;
import com.bdqn.service.ICourseTypeService;
import com.bdqn.service.IMinutiaService;
import com.bdqn.service.ISectionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 忍
 * @title: CourseServiceImp
 * @projectName Teaching
 * @description: TODO
 * @date 2019/6/189:34
 */
@Service
public class CourseServiceImp implements ICourseService {
    @Qualifier("ICourseDao")
    @Autowired
    private ICourseDao courseDao;
    @Autowired
    private ISectionService sectionService;
    @Autowired
    IMinutiaService minutiaService;
    @Autowired
    ICourseTypeService courseTypeService;
    /**
     * @param id 课程id
     * @return com.bdqn.bean.course.Course
     * @throws
     * @description: 根据课程id查询课程
     * @author Mr.Zhou
     * @date 2019/6/17 22:16
     */
    @Override
    public Course getCourseById(int id) {
        Course course = courseDao.getCourseById(id);
        List<Section> section = sectionService.getSectionByMinutiaId(course.getId());
        for (Section s:
             section) {
            List<Minutia> minutia = minutiaService.getMinutiaByCourseId(s.getsId());
            s.setMinutias(minutia);
        }
        course.setSections(section);
        return course;
    }

    /**
     * @param CouseTypeId
     * @return java.util.List<com.bdqn.bean.course.Course>
     * @throws
     * @description: 根据课程类型 id获取课程
     * @author Mr.Zhou
     * @date 2019/6/17 22:17
     */
    @Override
    public List<Course> getCoursesByCourseType(int CouseTypeId) {
        return null;
    }

    /**
     * @param directId
     * @param typeId
     * @param level
     * @param sort
     * @param unlearn
     * @return java.util.List<com.bdqn.bean.course.Course>
     * @throws
     * @description: 根据各种条件获取课程
     * @author Mr.Zhou
     * @date 2019/6/29 22:10
     */
    @Override
    public List<CourseDirection> getCourseByDirectId(Integer directId, Integer typeId, String level, String sort, String unlearn,Integer courseId) {
        if (typeId!=null && typeId!=0){
            //当课程类型的id不为空时更新点击量
            courseTypeService.updateClick(typeId);
        }
        return courseDao.getCourseByDirectId(directId,typeId,level,sort,unlearn,courseId);
    }

    public List<CourseDirection> getCourseMesById(Integer courseId){
        return courseDao.getCourseByDirectId(null,null,null,null,null,courseId);
    }
}
